package fido;


import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

public class DefaultTorrentImpl implements Torrent {

    private String name;
    private String torrentUrl;
    private String detailsPageUrl;
    private int seeders;
    private int leechers;
    private String cookie;
    private String torrentSiteName;

    public DefaultTorrentImpl() {

    }

    public final String getName() {
        return name;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public final String getTorrentUrl() {
        return torrentUrl;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public final String getDetailsPageUrl() {
        return detailsPageUrl;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public final int getSeeders() {
        return seeders;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public final int getLeechers() {
        return leechers;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public final String getCookieString() {
        return this.cookie;
    }

    @Override
    public String getTorrentSiteName() {
        return torrentSiteName;
    }

    public final File download(String pathAndFileName) {
        try {

            File downloadFile = FidoCommonUtils.downloadFile(new URL(this.torrentUrl), pathAndFileName, this.cookie);
            if (downloadFile != null) {
                return downloadFile;
            } else {
                throw new fido.exceptions.DownloadException("Couldn't download" + torrentUrl + ".");
            }

        } catch (MalformedURLException e) {
            e.printStackTrace();
            throw new fido.exceptions.DownloadException("Couldn't download" + torrentUrl + ": " + e.getMessage());
        } catch (IOException e) {
            e.printStackTrace();
            throw new fido.exceptions.DownloadException("Couldn't save " + torrentUrl + ": " + e.getMessage());
        }
    }

    public final void setName(String name) {
        this.name = name;
    }

    public final void setTorrentUrl(String torrentUrl) {
        this.torrentUrl = torrentUrl;
    }

    public final void setDetailsPageUrl(String detailsPageUrl) {
        this.detailsPageUrl = detailsPageUrl;
    }

    public final void setSeeders(int seeders) {
        this.seeders = seeders;
    }

    public final void setLeechers(int leechers) {
        this.leechers = leechers;
    }

    public final void setCookie(String cookie) {
        this.cookie = cookie;
    }

    @Override
    public void setTorrentSiteName(String torrentSiteName) {
        this.torrentSiteName = torrentSiteName;
    }
}
